package top.huntwolf.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.huntwolf.admin.common.JsonResult;
import top.huntwolf.admin.pojo.Exhibition;
import top.huntwolf.admin.service.ExhibitionService;
import top.huntwolf.admin.utils.UUIDUtil;

@RestController
@CrossOrigin
@RequestMapping(value = "/exhibition")
@Api(description = "栏目配置接口")
public class ExhibitionController {
    @Autowired
    ExhibitionService exhibitionService;

    // 查  -- 获取所有栏目表信息
    @GetMapping("")
    @ApiOperation("获取所有栏目表信息")
    public JsonResult getSelectedList(){
        return JsonResult.success(exhibitionService.searchAllExhibition());
    }

    // 查 -- 根据栏目id返回书籍列表
    @ApiOperation("根据栏目id返回书籍列表")
    @GetMapping("/{eid}")
    public JsonResult getBookList(@PathVariable String eid) {
        return JsonResult.success(exhibitionService.searchExhibitionById(eid));
    }

    // 改
    @ApiOperation("更新栏目信息")
    @PutMapping("")
    public JsonResult updateExhibition(@RequestBody Exhibition exhibition) {
        exhibitionService.updateSearchExhibition(exhibition);
        return JsonResult.success(null);
    }

    @ApiOperation("插入栏目信息")
    @PostMapping("/insert")
    public JsonResult insertExhibition(@RequestBody Exhibition exhibition){
        exhibition.setExhibitId(UUIDUtil.getUUID());
        exhibitionService.insertExhibition(exhibition);
        return JsonResult.success(exhibition);
    }

    // 分页显示对应栏目下的书本
    @GetMapping("/{eid}/pageNum/{pageNum}/pageSize/{pageSize}")
    @ApiOperation("小程序获取栏目书籍接口")
    public JsonResult queryBookInfo(@PathVariable String eid, @PathVariable int pageNum,@PathVariable int pageSize){
        return JsonResult.success(exhibitionService.searchBookInfo(eid, pageNum,pageSize));
    }
}
